package com.samebuilding.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

import com.samebuilding.dao.GiftCategoryDAO;
import com.samebuilding.domain.GiftCategory;

public class GiftCategoryDAOImpl extends HibernateDaoSupport implements GiftCategoryDAO{

	public int findCode(String name) {
		List list=this.getHibernateTemplate().find("from GiftCategory as g where g.name=?",name);
		if(list!=null&&list.size()>0){
			GiftCategory g=(GiftCategory)list.get(0);
			return g.getCode();
		}
		return 0;
	}

	public String findName(int code) {
		List list=this.getHibernateTemplate().find("from GiftCategory as g where g.code=?",code);
		if(list!=null&&list.size()>0){
			GiftCategory g=(GiftCategory)list.get(0);
			return g.getName();
		}
		return null;
	}

	public void save(GiftCategory gc) {
		this.getHibernateTemplate().save(gc);
		
	}
	
	public List findAll() {
		List  list=this.getHibernateTemplate().find("select distinct(gc) from GiftCategory gc left join fetch gc.gifts ");
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+list.size());
		return list;
	}

}
